package main.chapter2

fun main() {
    val people = People("温柔", "甜美", "动听")
    people.singASong("说好不哭")
    people.dance("流行舞蹈")
    val a = A()
    println(a.b)
}

class People(character: String, look: String, sound: String) {
    fun singASong(songName: String) {
        println("唱歌：$songName")
    }

    fun dance(danceName: String) {
        println("跳舞：$danceName")
    }
}

class A {
    var b = 0
        //kotlin默认实现了getter与setter如果想在其中做一些操作的话可以重写
        get() {
            println("someone want to get b")
            //这里非field代表实际的b
            return field
        }
        set(value) {
            println("set value to b")
            field = value
        }
    //val属性没有setter方法
    val c = "你好"
        get() {
            println("someone want to get c")
            return field
        }
}

open class B {
    var c = 0
        protected set
}

class D
class C {
    //需要初始化值，可以使用基本类型的默认值来进行初始化
    var d = 0
    var e: String = ""
    var f: Boolean = false
    //lateinit var延迟初始化不能用于val
    lateinit var g: D
    val h: D by lazy {
        println("延迟初始化h")
        D()
    }
}